﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement.AsyncOperations;
//11.加载：通过Label批量加载
public class Example4 : MonoBehaviour
{

    private void Start()
    {
        
    }
    private void OnGUI()
    {
        if (GUILayout.Button("通过Label批量加载"))
        {
            //有一个monsters是在Remote上，如果是Player Mode Script = Packed Play Mode,需要起Hosting
            Addressables.LoadAssetsAsync<GameObject>("monsters", t=>{
                Debug.Log(t.name);

            }).Completed += e =>
            {
                Debug.Log(e.Result.Count);

                //所有加载完之后，可以实例化
                foreach(var prefab in e.Result)
                {
                    Instantiate(prefab);
                }
            };
        }
        if (GUILayout.Button("通过地址+标签批量加载"))
        {
            //MergeMode.UseFirst 只使用到“Archers”作为查询条件，“CharacterDefault”忽略掉了
            //MergeMode.Union 并集
            //MergeMode.Intersection 交集
            Addressables.LoadAssetsAsync<Texture>(new List<object> { "Archers","CharacterDefault" }, t => {
                Debug.Log(t.name);

            },Addressables.MergeMode.Intersection).Completed += e =>
            {
                Debug.Log(e.Result.Count);
            };
        }
        
        
        
    }




}
